﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Speedy
{
    public class dbRoute : MasterTable
    {
        public Column id { get; set; }
        public Column visit_no { get; set; }
        public Column week_no { get; set; }
        public Column day_no { get; set; }
        public Column customer_id { get; set; }
        public Column merchant_id { get; set; }
        public Column address_id { get; set; }

        public dbRoute()
        {
            this.id = new Column(typeof(int), "ID", 4, false, false, true);
            this.visit_no = new Column(typeof(int), "VISIT_NO", 4);
            this.week_no = new Column(typeof(int), "WEEK_NO", 4, false, true);
            this.day_no = new Column(typeof(int), "DAY_NO", 4, false, true);
            this.customer_id = new Column(typeof(int), "CUSTOMER_ID", 4, false, true);
            this.merchant_id = new Column(typeof(int), "MERCHANT_ID", 4, false, true);
            this.address_id = new Column(typeof(int), "ADDRESS_ID", 4, false, true);

            this.TableName = "MERCHANT_ROUTE";
            this.Columns.Add(this.id);
            this.Columns.Add(this.visit_no);
            this.Columns.Add(this.week_no);
            this.Columns.Add(this.day_no);
            this.Columns.Add(this.customer_id);
            this.Columns.Add(this.merchant_id);
            this.Columns.Add(this.address_id);
        }

        public override void Remove()
        {
            string where = string.Empty;
            ParameterCollection prm = new ParameterCollection();

            foreach (Column col in this.Columns)
            {
                if (col.Name == "WEEK_NO" || col.Name == "DAY_NO" || col.Name == "MERCHANT_ID")
                {
                    where += col.Name + "=@" + col.Name + " and ";
                    prm.AddItem(Prm.Get("@" + col.Name, col.Read()));
                }
            }

            where = where.Remove(where.Length - 4, 4);

            StringBuilder sb = new StringBuilder();
            sb.Append(string.Format("delete from {0} where {1} ", this.TableName, where));

            DataLayer.GetLayer.ExecQuery(sb.ToString(), prm.ToArray());
        }

    }
}
